package com.share.controller;

import com.share.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author sunxuejian
 * @date 2020/4/28
 */
@Controller
@RequestMapping("/hello")
public class C1_helloController {

    @RequestMapping("/say")
    public String hello() {
        return "hello";
    }

    @RequestMapping("/show")
    @ResponseBody
    public String hello1() {
        return new User().setName("sunxj").setAge(26).toString();
    }

    //http://localhost:8080/sunxj-springmvc02/hello/user
    @RequestMapping("/user")
    @ResponseBody
    public User showUser() {
        return new User().setName("sunxj").setAge(26);
    }

    //http://localhost:8080/sunxj-springmvc02/hello/redirect-in
    //本类重定向
    @RequestMapping("/redirect-in")
    public String redirectIn() {
        return "redirect:/hello/say";
    }

    //http://localhost:8080/sunxj-springmvc02/hello/redirect-out
    //外部重定向
    @RequestMapping("/redirect-out")
    public String redirectOut() {
        return "redirect:/items/say";
    }


    //http://localhost:8080/sunxj-springmvc02/hello/forward-in
    //本类转发
    @RequestMapping("/forward-in")
    public String forwordIn() {
        return "forward:say";
    }

    //http://localhost:8080/sunxj-springmvc02/hello/forward-out
    //外部转发
    @RequestMapping("/forward-out")
    public String forwordOut() {
        return "forward:/items/say";
    }
}
